package no.kolstad.moviesdatabase.moviesdatabase.core.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.appfuse.model.BaseObject;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Copyright [2008] [Christopher Kolstad] Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 * Unless required by applicable law or agreed to in writing, 
 * software distributed under the License is distributed 
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and limitations under the License. 
 * @author chriswk
 */
@Entity
public class Borrower extends BaseObject implements Serializable{
    private Long id;
    private String firstName;
    private String lastName;
    private Set<Movie> borrowedMovies = new HashSet<Movie>();

  @OneToMany
  public Set<Movie> getBorrowedMovies() {
    return borrowedMovies;
  }

  public void setBorrowedMovies(Set<Movie> borrowedMovies) {
    this.borrowedMovies = borrowedMovies;
  }

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }
  
  @Id @GeneratedValue
  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Borrower other = (Borrower) obj;
    if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
      return false;
    }
    return true;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 53 * hash + (this.id != null ? this.id.hashCode() : 0);
    hash = 53 * hash + (this.firstName != null ? this.firstName.hashCode() : 0);
    hash = 53 * hash + (this.lastName != null ? this.lastName.hashCode() : 0);
    return hash;
  }

  @Override
  public String toString() {
    return new ToStringBuilder(this)
        .append("[ID]")
        .append(id)
        .append("[FirstName]")
        .append(firstName)
        .append("[LastName]")
        .append(lastName)
        .toString();
  }

}
